package logic

import (
	"context"
	"fmt"
	"novel/model/mysql"
	"strings"

	"novel/novelrpc/internal/svc"
	"novel/novelrpc/novelrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CourseAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCourseAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CourseAddLogic {
	return &CourseAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CourseAddLogic) CourseAdd(in *novelrpc.CourseAddRequest) (*novelrpc.CourseAddResponse, error) {
	// todo: add your logic here and delete this line

	var course mysql.Course
	course = mysql.Course{
		UserId:  int(in.UserId),
		NovelId: int(in.NovelId),
		Ifor:    in.Ifor,
	}
	if strings.Contains(in.Ifor, "抄袭") || strings.Contains(in.Ifor, "涉政") {
		return nil, fmt.Errorf("涉嫌敏感词,请重新输入")
	}
	mysql.DB.Debug().Create(&course)

	return &novelrpc.CourseAddResponse{
		CourseId: int64(course.ID),
	}, nil
}
